package com.itheima.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.itheima.dao.UserDao;
import com.itheima.dao.impl.UserDaoimpl;
import com.itheima.pojo.User;
import com.itheima.service.UserService;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;

public class UserServiceimpl implements UserService {
    private UserDao userDao = new UserDaoimpl();
    @Override
    public List<User> list() {
        List<String> stringList = userDao.list();
        List<User> list = stringList.stream().map(s -> {
            String[] split = s.split(",");
            Integer id = Integer.parseInt(split[0]);
            String username = split[1];
            String password = split[2];
            String name = split[3];
            Integer age = Integer.parseInt(split[4]);
            LocalDateTime updatetime = LocalDateTimeUtil.parse(split[5], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new User(id, username, password, name, age, updatetime);
        }).collect(Collectors.toList());
        return list;

    }
}
